#ifndef STANDARDITEMMODEL_H
#define STANDARDITEMMODEL_H
#include <QStandardItemModel>
#include <QJsonObject>

class StandardItemModel : public QStandardItemModel
{
    Q_OBJECT
public:
    StandardItemModel(QObject *parent = 0);
public slots:    
    QModelIndex appendRow(const QModelIndex &index, const QVariantMap &data);
    void appendRows(const QModelIndex &index, const QVariantList &list);
    void appendChildren(const QModelIndex &index, const QVariantList &list);
    QModelIndex appendChild(const QModelIndex &index, const QVariantMap &data);
    void removeRow(const QModelIndex & index);
    void insertRow(int row, const QVariantMap &data, const QModelIndex & parent);

    QVariant itemData(const QModelIndex & index, const QString &name) const;
    void setItemData(const QModelIndex & index, const QVariant & value, const QString &name);
    QVariantList treeData();
    int level(const QModelIndex & index);
    QVariantList pathData(const QModelIndex & index);
	void clear();

    QModelIndex parent(const QModelIndex & index);
    //QModelIndex index(int row, const QModelIndex &parent) const;
    bool hasParent(const QModelIndex &index);
    bool hasChildren(const QModelIndex &index) const;


    int rowCount(const QModelIndex &parent) const;
    QModelIndex index(int row, const QModelIndex &parent) const;
    QModelIndex siblingIndex(int row, const QModelIndex & index) const;
    bool moveUp( const QModelIndex &index);
    bool moveDown( const QModelIndex &index);
protected:
    virtual QHash<int, QByteArray> roleNames() const;
    virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild);
private:
    QModelIndex append(QStandardItem *parent, const QVariantMap &data);
    void exported(QStandardItem * item, QVariantList &list);
    int role(const QString &name);
    void loop(QStandardItem *parent, const QVariantList &data);
};

#endif // STANDARDITEMMODEL_H
